﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using BASE;
using Aspose.Cells;
using Aspose.Words;




public partial class Report_xemDiemThi : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (Utils.getStringSession("masv") == "")
        {
            Response.Write("/");
        }
        ExportToExcel("");
    }

    public void ExportToExcel(string fileName)
    {
        int intCurentRow = 2;
        //Create a new workbook
        Workbook workbook = new Workbook();
        string strPath = Server.MapPath("~/Template/bangdiem.xls");
        workbook.Open(strPath);
        Worksheet sheet1 = workbook.Worksheets[0];
        Cells cell = sheet1.Cells;
        cell[intCurentRow, 0].PutValue("g");

        List<entDiem> lst = new List<entDiem>();
        busDiem busD = new busDiem();
        List<entDiem> lst2 = new List<entDiem>();


        lst = busD.getNamHocHocKy(Utils.getStringSession("masv"));

        int count = 1;
        int row = 0;
        foreach (entDiem item in lst)
        {
            lst2 = busD.getDiemHocKy(item.NamHoc, item.HocKy, Utils.getStringSession("masv"));
            row = intCurentRow;
            cell.Merge(row, 0, 1, 7);
            int hk;
            if (item.HocKy.ToUpper() == "hk1".ToUpper())
            {
                hk = 1;
            }
            else
            {
                hk = 2;
            }

            cell[row, 0].PutValue("Học kỳ " + hk + " năm " + item.NamHoc );
            foreach (entDiem item2 in lst2)
            {
                intCurentRow++;
                row = intCurentRow;
                cell[row, 0].PutValue(count++);
                cell[row, 1].PutValue(item2.MaMon);
                cell[row, 2].PutValue(item2.TenMon);
                Aspose.Cells.Style style;
                style = cell[row, 3].GetStyle();
                style.HorizontalAlignment = TextAlignmentType.Center;
                cell[row, 3].SetStyle(style);
                style = cell[row, 4].GetStyle();
                style.HorizontalAlignment = TextAlignmentType.Center;
                cell[row, 4].SetStyle(style);
                style = cell[row, 5].GetStyle();
                style.HorizontalAlignment = TextAlignmentType.Center;
                cell[row, 5].SetStyle(style);
                style = cell[row, 5].GetStyle();
                style.HorizontalAlignment = TextAlignmentType.Center;
                cell[row, 6].SetStyle(style);
                cell[row,3].PutValue(item2.SoTC);
                cell[row,4].PutValue(item2.Diem);
                cell[row,5].PutValue(item2.DiemH4);
                cell[row, 6].PutValue(item2.DiemC);
            }
            intCurentRow++;

        }

        workbook.Save("bangdiem.xls", Aspose.Cells.SaveType.OpenInBrowser, FileFormatType.Default, this.Response);
    }
}